//
//  DataCollectLog.m
//  MarketDataColloctor
//
//  Created by jiro on 10/03/09.
//  Copyright 2010 jiro music. All rights reserved.
//

#import "DataCollectLog.h"

@implementation DataCollectLog

@synthesize code0;
@synthesize code1;
@synthesize	latestDate;
@synthesize marketDataType;

+ (NSString*) tableName;
{
	return kText_DataCollectLogTable;
}

+ (NSString*) queryCreateTable
{
	NSString* s = [ NSString stringWithFormat: 
		@"create table %@ ( %@ %@, %@ %@, %@ %@, %@ %@, %@( %@, %@, %@, %@ ) );",
			[ DataCollectLog tableName ], 
			kText_Code0, kText_Text,
			kText_Code1, kText_Text,
			kText_MarketDataType, kText_Integer,
			kText_LatestDate, kText_TimestampWithTimeZone,
			kText_PrimaryKey, kText_Code0, kText_Code1, kText_MarketDataType, kText_LatestDate
	];
	return s;
}

+ (id) dataCollectLogWithDbValues: (NSArray*) values
{
	DataCollectLog*	log	= [ [ DataCollectLog alloc ] init ];
	log.code0			= [ values objectAtIndex: 0 ];
	log.code1			= [ values objectAtIndex: 1 ];
	log.marketDataType	= (MarketData::Type) [ [ values objectAtIndex: 2 ] intValue ];
	log.latestDate		= [ NSDate dateWithString: [ DbUtility convertIsoStdDateStringToCocoaDateString: [ values objectAtIndex: 3 ] ] ];
	return log;
}


- (NSString*) tableName
{
	return [ DataCollectLog tableName ];
}

- (NSString*) sqlInsertStatement
{
	return [ NSString stringWithFormat: @"insert into %@ values %@;", [ DataCollectLog tableName ], [ self queryInsertValue ] ];
}

+ (NSString*) querySelectAll
{
	NSString* s = [ NSString stringWithFormat: @"select * from %@;", [ DataCollectLog tableName ] ];
	return s;
}

- (NSString*) queryInsert
{
	NSString* s = [ NSString stringWithFormat: @"insert into %@ values %@;", 
		[ DataCollectLog tableName ], [ self queryInsertValue ] ];
	return s;
}

- (NSString*) queryInsertValue
{
	return [ NSString stringWithFormat: @"( '%@', '%@', %d, '%@' )",
		code0, code1, marketDataType, [ latestDate description ] ];
}

@end
